package com.leyou.item.controller;

import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import com.leyou.item.service.SpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: wzh
 * @Date: 2019/3/23 04:41
 * @Description:商品规格组+规格参数 Controller
 */
@RestController
@RequestMapping("spec")
public class SpecificationController {

    @Autowired
    private SpecificationService specService;



    /**
     * 根据分类id查询规格组
     * @param cid
     * @return
     */
    @GetMapping("groups/{cid}")
    public ResponseEntity<List<SpecGroup>> queryGroupByCid(@PathVariable("cid") Long cid){

        return ResponseEntity.ok(specService.queryGroupCid(cid));

    }

    /**
     * 查询参数的集合
     * @param gid 规格组id 根据规格组id查询规格参数
     * @param cid 商品分类id 根据商品分类id查询规格参数
     * @param searching 是否用于搜索过滤，true或false
     * @param generic 是否是sku通用属性，true或false
     * @return
     */
    @GetMapping("/params")
    public ResponseEntity<List<SpecParam>> queryParamList(
            @RequestParam(value="gid", required = false) Long gid,
            @RequestParam(value="cid", required = false) Long cid,
            @RequestParam(value="searching", required = false) Boolean searching,
            @RequestParam(value="generic", required = false) Boolean generic){

        return ResponseEntity.ok(specService.queryParamList(gid,cid,searching,generic));
    }

    /**
     * 根据分类查询规格组及组内参数
     * @param cid
     * @return
     */
    @GetMapping("{cid}")
    public ResponseEntity<List<SpecGroup>> querySpecsByCid(@PathVariable("cid") Long cid){
        return ResponseEntity.ok(specService.queryListById(cid));
    }

}
